package com.foreknow.springboot.controller;

import com.foreknow.springboot.po.Cart;
import com.foreknow.springboot.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaoming
 * @version jdk1.8
 * @date 2022/8/13 17:46
 * @function:
 */
@RestController
@RequestMapping("/CartController")
public class CartController {
    @Autowired
    private CartService cartService;

    //http://localhost:8089/elm/CartController/listCart?userId=1234567
    //http://localhost:8089/elm/CartController/listCart?userId=1234567&businessId=10001
    @RequestMapping("/listCart")
    public List<Cart> listCart(Cart cart){
        return cartService.listCart(cart);
    }

    //http://localhost:8089/elm/CartController/saveCart?userId=1234567&businessId=10001&foodId=2
    @RequestMapping("/saveCart")
    public int saveCart(Cart cart){
        return cartService.saveCart(cart.getUserId(),cart.getBusinessId(),cart.getFoodId());
    }

    //http://localhost:8089/elm/CartController/updateCart?quantity=5&userId=1234567&businessId=10001&foodId=2
    @RequestMapping("/updateCart")
    public int updateCart(Cart cart){
        return cartService.updateCart(cart.getUserId(),cart.getBusinessId(),cart.getFoodId(),cart.getQuantity());
    }
    //http://localhost:8089/elm/CartController/removeCart?userId=1234567&businessId=10001
    //http://localhost:8089/elm/CartController/removeCart?userId=1234567&businessId=10001&foodId=2
    @RequestMapping("/removeCart")
    public int removeCart(Cart cart){
        return cartService.removeCart(cart);
    }



}
